<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of random</title>
  <meta name="keywords" content="random">
  <meta name="description" content="random --- overwrite g with a random graph">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="../index.html">matgraph</a> &gt; <a href="index.html">@graph</a> &gt; random.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for matgraph/@graph&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>random
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>random --- overwrite g with a random graph</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function random(g,arg1,arg2) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> random --- overwrite g with a random graph
 random(g,n,p) --- overwrite g with an Erdos-Renyi G(n,p) graph
 random(g,p) --- overwrite g with an Erdos-Reniy G(n,p) graph where n is
                 the number of vertices already in g.
 random(g) --- equivalent to random(g,1/2)</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="fast_set_matrix.html" class="code" title="function fast_set_matrix(g,A)">fast_set_matrix</a>	fast_set_matrix(g,A) --- overwrite the adjacency matrix of g with A</li><li><a href="nv.html" class="code" title="function n = nv(g)">nv</a>	nv(g) --- number of vertices in g</li><li><a href="random.html" class="code" title="function random(g,arg1,arg2)">random</a>	random --- overwrite g with a random graph</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="random.html" class="code" title="function random(g,arg1,arg2)">random</a>	random --- overwrite g with a random graph</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function random(g,arg1,arg2)</a>
0002 <span class="comment">% random --- overwrite g with a random graph</span>
0003 <span class="comment">% random(g,n,p) --- overwrite g with an Erdos-Renyi G(n,p) graph</span>
0004 <span class="comment">% random(g,p) --- overwrite g with an Erdos-Reniy G(n,p) graph where n is</span>
0005 <span class="comment">%                 the number of vertices already in g.</span>
0006 <span class="comment">% random(g) --- equivalent to random(g,1/2)</span>
0007 
0008 
0009 
0010 <span class="comment">% case: random(g,n,p)</span>
0011 
0012 <span class="keyword">if</span> nargin==3
0013     n = arg1;
0014     p = arg2;
0015     
0016     A = triu(rand(n,n)&lt;=p);
0017     A = A+A';
0018     <span class="keyword">for</span> k=1:n
0019         A(k,k)=0;
0020     <span class="keyword">end</span>
0021     <a href="fast_set_matrix.html" class="code" title="function fast_set_matrix(g,A)">fast_set_matrix</a>(g,A);
0022     <span class="keyword">return</span>
0023 <span class="keyword">end</span>
0024 
0025 <span class="comment">% case: random(g,p)</span>
0026 
0027 <span class="keyword">if</span> nargin==2
0028     n = <a href="nv.html" class="code" title="function n = nv(g)">nv</a>(g);
0029     p = arg1;
0030     <a href="random.html" class="code" title="function random(g,arg1,arg2)">random</a>(g,n,p);
0031     <span class="keyword">return</span>
0032 <span class="keyword">end</span>
0033 
0034 <span class="comment">% last case: random(g)</span>
0035 
0036 <a href="random.html" class="code" title="function random(g,arg1,arg2)">random</a>(g,0.5);</pre></div>
<hr><address>Generated on Fri 30-Apr-2010 07:51:16 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>